const captcha = require('svg-captcha');
const jwt = require('../../lib/jtw.lib');
const cache = require('../../lib/cache.lib');


/**
 * 验证码服务
 */
class CaptchaService {
    constructor() { }
    createCaptcha() {
        let data = captcha.create({
            ignoreChars: '0o1i',
            fontSize:30,
            width: 80,
            height: 30}),
            token = jwt.generateToken(data.text);
        cache.setCache(token, data.text.toUpperCase());
        let result = {
            token,
            captacha: data.data
        }
        return result;
    }
}



module.exports = global.buildClass(CaptchaService);